home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_051 / bison / simparser < prev    next >
Text File  |  1992-05-06  |  9KB  |  343 lines

  1. #line 2 "simparser.c"
  2.  
  3. /* Skeleton output parser for bison,
  4.    copyright (C) 1984 Bob Corbett and Richard Stallman
  5.  
  6.    Permission is granted to anyone to make or distribute verbatim copies of this program
  7.    provided that the copyright notice and this permission notice are preserved;
  8.    and provided that the recipient is not asked to waive or limit his right to
  9.    redistribute copies as permitted by this permission notice;
  10.    and provided that anyone possessing an executable copy
  11.    is granted access to copy the source code, in machine-readable form,
  12.    in some reasonable manner.
  13.  
  14.    Permission is granted to distribute derived works or enhanced versions of
  15.    this program under the above conditions with the additional condition
  16.    that the entire derivative or enhanced work
  17.    must be covered by a permission notice identical to this one.
  18.  
  19.    Anything distributed as part of a package containing portions derived
  20.    from this program, which cannot in current practice perform its function usefully
  21.    in the absense of what was derived directly from this program,
  22.    is to be considered as forming, together with the latter,
  23.    a single work derived from this program,
  24.    which must be entirely covered by a permission notice identical to this one
  25.    in order for distribution of the package to be permitted.
  26.  
  27.  In other words, you are welcome to use, share and improve this program.
  28.  You are forbidden to forbid anyone else to use, share and improve
  29.  what you give them.   Help stamp out software-hoarding!  */
  30.  
  31. /* This is the parser code that is written into each bison parser
  32.   when the %semantic_parser declaration is not specified in the grammar.
  33.   It was written by Richard Stallman by simplifying the hairy parser
  34.   used when %semantic_parser is specified.  */
  35.  
  36. /* Note: there must be only one dollar sign in this file.
  37.    It is changed into a #include that includes the action file.  */
  38.  
  39. #define yyerrok        (yyerrstatus = 0)
  40. #define yyclearin    (yychar1 = -2)
  41.  
  42. #define YYTERROR    1
  43.  
  44. #ifndef YYIMPURE
  45. #define YYLEX        yylex()
  46. #endif
  47.  
  48. #ifndef YYPURE
  49. #define YYLEX        yylex(&yylval, &yylloc)
  50. #endif
  51.  
  52. /* If nonreentrant, generate the variables here */
  53.  
  54. #ifndef YYIMPURE
  55.  
  56. int    yychar;            /*  the lookahead symbol        */
  57. YYSTYPE    yylval;            /*  the semantic value of the        */
  58.                 /*  lookahead symbol            */
  59.  
  60. YYLTYPE yylloc;            /*  location data for the lookahead    */
  61.                 /*  symbol                */
  62.  
  63. int yydebug = 0;        /*  nonzero means print parse trace    */
  64.  
  65. #endif  /* YYIMPURE */
  66.  
  67.  
  68. /*  YYMAXDEPTH indicates the size of the parser's state and value    */
  69. /*  stacks.                                */
  70.  
  71. #ifndef    YYMAXDEPTH
  72. #define    YYMAXDEPTH    250
  73. #endif
  74.  
  75. int
  76. yyparse()
  77. {
  78.   register int yystate;
  79.   register int yyn;
  80.   register short *yyssp;
  81.   register YYSTYPE *yyvsp;
  82.   YYLTYPE *yylsp;
  83.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  84.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  85.  
  86.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  87.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  88.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  89.  
  90.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  91.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  92.   YYLTYPE *yyls = yylsa;
  93.  
  94.   int yymaxdepth = YYMAXDEPTH;
  95.  
  96. #ifndef YYPURE
  97.  
  98.   int yychar;
  99.   YYSTYPE yylval;
  100.   YYLTYPE yylloc;
  101.  
  102.   extern int yydebug;
  103.  
  104. #endif
  105.  
  106.  
  107.   YYSTYPE yyval;        /*  the variable used to return        */
  108.                 /*  semantic values from the action    */
  109.                 /*  routines                */
  110.  
  111.   int yylen;
  112.  
  113.   yystate = 0;
  114.   yyerrstatus = 0;
  115.   yychar1 = 1;   /* just to cause a proper refill */
  116.  
  117.   yyssp = yyss - 1;
  118.   yyvsp = yyvs - 1;
  119.   yylsp = yyls - 1;
  120.  
  121. yyrefill:
  122. /* at end of file, yychar is <= 0 and yychar1 is 0.
  123.  After shifting error token, if should reuse the lookahead token,
  124.   yychar is that token in external form and yychar1 is -1.
  125.  After shifting error token, if should discard the lookahead token,
  126.   yychar is the token to be discarded and yychar1 is 100000.
  127.  After yyclearin has been done, yychar1 is -2.
  128.  After normal token processing, yychar1 is positive. */
  129.  
  130.   if (yychar1 > 0) yychar = YYLEX;
  131.   if (yychar <= 0)
  132.     yychar1 = 0;
  133.   else yychar1 = YYTRANSLATE(yychar);
  134.  
  135.   if (yydebug)
  136.     fprintf(stderr, "Next token is type %d\n", yychar);
  137.  
  138. yynewstate:
  139.  
  140.   *++yyssp = yystate;
  141.  
  142.   if (yyssp >= yyss + yymaxdepth - 1)
  143.     {
  144. #ifdef yyoverflow
  145.       /* Give user a chance to reallocate the stack */
  146.       int yyssize = yyssp-yyss, yylsize = yylsp-yyls, yyvsize = yyvsp-yyvs;
  147.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  148.       YYSTYPE *yyvs1 = yyvs;
  149.       YYLTYPE *yyls1 = yyls;
  150.       short *yyss1 = yyss;
  151.  
  152.       /* Each stack pointer address is followed by the size of
  153.      the data in use in that stack, in bytes.  */
  154.       yyoverflow("parser stack overflow",
  155.          &yyss1, (yyssize+1)*sizeof(*yyssp), &yyvs1, (yyvsize+1)*sizeof(*yyvsp),
  156.          &yyls1, (yylsize+1)*sizeof(*yylsp), &yymaxdepth);
  157.  
  158.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  159.  
  160.       yyssp = yyss+yyssize;
  161.       yylsp = yyls+yylsize;
  162.       yyvsp = yyvs+yyvsize;
  163.  
  164.       if (yyssp >= yyss + yymaxdepth - 1)
  165.     YYERROR;
  166. #endif
  167.  
  168. #ifndef yyoverflow
  169.       yyerror("parser stack overflow");
  170. #endif
  171.     }
  172.  
  173.   if (yydebug)
  174.     fprintf(stderr, "Entering state %d\n", yystate);
  175.  
  176. yyresume:
  177.  
  178.   yyn = yypact[yystate];
  179.   if (yyn == YYFLAG)
  180.     goto yydefault;
  181.  
  182.   yyn += yychar1;
  183.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  184.     goto yydefault;
  185.  
  186.   yyn = yytable[yyn];
  187.   if (yyn < 0)
  188.     {
  189.       yyn = -yyn;
  190.       goto yyreduce;
  191.     }
  192.   else if (yyn == 0)
  193.     goto yyerrlab;
  194.  
  195.   if (yyn == YYFINAL)
  196.     YYACCEPT;
  197.  
  198.   if (yydebug)
  199.     fprintf(stderr, "Shifting token %d, ", yychar);
  200.  
  201.   *++yyvsp = yylval;
  202.   *++yylsp = yylloc;
  203.  
  204.   /* count tokens shifted since error; after three, turn off error status.  */
  205.   if (yyerrstatus) yyerrstatus--;
  206.  
  207.   yystate = yyn;
  208.   goto yyrefill;
  209.  
  210. yydefault:
  211.  
  212.   yyn = yydefact[yystate];
  213.   if (yyn == 0)
  214.     goto yyerrlab;
  215.  
  216. yyreduce:
  217.   /* yyn is the number of a rule to reduce with.  */
  218.  
  219.   if (yydebug)
  220.     fprintf(stderr, "Reducing via rule %d, ", yyn);
  221.  
  222.   yylen = yyr2[yyn];
  223.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  224.  
  225. $   /* this dollarsign gets turned into a #include of the action file */
  226.  
  227.   yyvsp -= yylen;
  228.   yylsp -= yylen;
  229.   yyssp -= yylen;
  230.  
  231.   if (yydebug)
  232.     fprintf(stderr, "popping to level %d\n", yyssp-yyss);
  233.  
  234.   *++yyvsp = yyval;
  235.  
  236.   yylsp++;
  237.   if (yylen == 0)
  238.     {
  239.       yylsp->first_line = yylloc.first_line;
  240.       yylsp->first_column = yylloc.first_column;
  241.       yylsp->last_line = (yylsp-1)->last_line;
  242.       yylsp->last_column = (yylsp-1)->last_column;
  243.       yylsp->text = 0;
  244.     }
  245.   else
  246.     {
  247.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  248.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  249.     }
  250.  
  251.   yyn = yyr1[yyn];
  252.  
  253.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  254.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  255.     yystate = yytable[yystate];
  256.   else
  257.     yystate = yydefgoto[yyn - YYNTBASE];
  258.  
  259.   if (yychar1 == -2)   /* detect use of yyclearin  */
  260.     { yychar1 = 1; goto yyrefill; }
  261.   /* want to reuse or discard token after error => do so. */
  262.   if (yychar1 < 0 || yychar1 == 100000)
  263.     goto yyrefill;
  264.   goto yynewstate;
  265.  
  266. yyerrlab:   /* here on detecting error */
  267.  
  268.   if (! yyerrstatus)
  269.     /* If not already recovering from an error, report this error.  */
  270.     {
  271.       yyerror("parse error");
  272.     }
  273.  
  274.   if (yyerrstatus == 3)
  275.     {
  276.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  277.       if (yydebug)
  278.     fprintf(stderr, "Discarding token %d.\n", yychar);
  279.  
  280.       yychar1 = 100000;  /* Make sure it really gets discarded. */
  281.  
  282.       /* return failure if at end of input */
  283.       if (yychar <= 0)
  284.     YYERROR;
  285.     }
  286.   else
  287.     {
  288.       /* Else try to reuse it after shifting the error token.  */
  289.       yychar1 = -1;
  290.     }
  291.  
  292.   yyerrstatus = 3;
  293.  
  294.   goto yyerrhandle;
  295.  
  296. yyerrdefault:  /* current state does not do anything special for the error token. */
  297.  
  298.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  299.   if (yyn) goto yydefault;
  300.  
  301. yyerrpop:   /* pop the current state because it cannot handle the error token */
  302.  
  303.   if (yyssp == yyss) YYERROR;
  304.   yyvsp--;
  305.   yylsp--;
  306.   yystate = *--yyssp;
  307.  
  308.   if (yydebug)
  309.     fprintf(stderr, "Error: Popping to level %d and state %d.\n", yyssp-yyss, yystate);
  310.  
  311. yyerrhandle:
  312.  
  313.   yyn = yypact[yystate];
  314.   if (yyn == YYFLAG)
  315.     goto yyerrdefault;
  316.  
  317.   yyn += YYTERROR;
  318.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  319.     goto yyerrdefault;
  320.  
  321.   yyn = yytable[yyn];
  322.   if (yyn < 0)
  323.     {
  324.       yyn = -yyn;
  325.       goto yyreduce;
  326.     }
  327.   else if (yyn == 0)
  328.     goto yyerrpop;
  329.  
  330.   if (yyn == YYFINAL)
  331.     YYACCEPT;
  332.  
  333.   if (yydebug)
  334.     fprintf(stderr, "Shifting error token, ");
  335.  
  336.   *++yyvsp = yylval;
  337.   *++yylsp = yylloc;
  338.  
  339.   yystate = yyn;
  340.   goto yyrefill;
  341.  
  342. }
  343.